<template>
  <div>
    <div class="background">
      <img src="../assets/lgb.jpg" width="100%" height="100%" alt="" />
    </div>
    <div class="front">
      <el-container>
        <el-header>
          <img src="../assets/logo.png" class="mlogo" />
          <h1 style="height: 30px">注册</h1>
        </el-header>
        <el-main>
          <el-row :gutter="20">
            <el-col :span="9" :offset="5">
              <el-card class="box-card"
                ><el-form
                  :model="ruleForm"
                  :rules="rules"
                  ref="ruleForm"
                  label-width="100px"
                  class="demo-ruleForm"
                >
                  <el-form-item label="姓名" prop="name">
                    <el-input
                      v-model="ruleForm.name"
                      prefix-icon="el-icon-s-custom"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="教师类型" prop="type">
                    <el-select
                      v-model="value"
                      clearable
                      placeholder="请选择"
                      style="width:300px"
                    >
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option> </el-select
                  ></el-form-item>
                  <el-form-item label="用户名" prop="username">
                    <el-input
                      v-model="ruleForm.username"
                      prefix-icon="el-icon-user-solid"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="密码" prop="password">
                    <el-input
                      v-model="ruleForm.password"
                      type="password"
                      prefix-icon="el-icon-key"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="身份证号" prop="idnumber">
                    <el-input
                      v-model="ruleForm.id_number"
                      prefix-icon="el-icon-notebook-2"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="电话" prop="phone">
                    <el-input
                      v-model="ruleForm.phone"
                      prefix-icon="el-icon-phone"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="电子邮箱" prop="email">
                    <el-input
                      v-model="ruleForm.email"
                      type="email"
                      prefix-icon="el-icon-message"
                    ></el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-row>
                      <el-col span="10" offset="2"
                        ><el-button
                          type="primary"
                          @click="submitForm('ruleForm')"
                          >提交</el-button
                        ></el-col
                      >
                      <el-col span="2"
                        ><el-button @click="returnForm('ruleForm')"
                          >返回</el-button
                        ></el-col
                      >
                    </el-row>
                  </el-form-item>
                </el-form></el-card
              ></el-col
            >
          </el-row>
        </el-main>
      </el-container>
    </div>
  </div>
</template>

<script>
export default {
  name: "Register",

  data() {
    return {
      ruleForm: {
        name: "ccc",
        type: "",
        password: "123456",
        username: "ccc",
        id_number: "3202302198812020214",
        phone: "17766120652",
        email: "2101185643@qq.com"
      },
      rules: {
        name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        type: [
          { required: false, message: "请选择教师类型", trigger: "change" }
        ],
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        id_number: [
          { required: true, message: "请输入身份证号", trigger: "blur" },
          { min: 18, max: 19, message: "请输入正确的身份证号", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { min: 10, max: 12, message: "请输入正确手机号", trigger: "blur" }
        ],
        email: [{ required: true, message: "请输入电子邮箱", trigger: "blur" }]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$axios.post("/register", this.ruleForm).then(res => {
            alert("注册成功!");
            this.$router.push("/login");
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    returnForm(formName) {
      this.$router.push("/login");
    }
  }
};
</script>

<style lang="scss" scoped>
.el-header,
.el-footer {
  /*  background-color: #b3c0d1;*/
  color: #333;
  text-align: center;
  line-height: 60px;
  height: 80% !important;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: transparent;
  color: #333;
  text-align: left;
  line-height: 160px;
}
.box {
  width: 500px !important;
}
body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.demo-ruleForm {
  max-width: 400px;
  margin: 0 auto;
}
.mlogo {
  height: 150px;
  margin-top: 10px;
}
.el-select .el-input__inner {
  cursor: pointer;
  padding-right: 35px;
  width: 300px !important;
}
.background {
  width: 100%;
  height: 120%; /**宽高100%是为了图片铺满屏幕 */
  z-index: -1 !important;
  position: absolute;
}
.front {
  z-index: 1 !important;
  background-color: transparent !important;
  margin: auto 0;
}
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 615px;
  background-color: white;
}
</style>
